var timeOut;

function getMyComplaintsTable(array){
	var a = jQuery.parseJSON(array);
	var even = "";
	var table = "<table class='myComplaintsTable'><tr>";
	
	table += "<th id='c.id'>" + a[0][0] + "</th>";
	table += "<th id='c.heading'>" + a[0][1] + "</th>";
	table += "<th id='c.date'>" + a[0][3] + "</th>";
	table += "<th id='applicant'>" + a[0][4] + "</th>";
	table += "<th id='c.priority'>" + a[0][5] + "</th>";
	table += "<th id='s.status'>" + a[0][6] + "</th>";

	table += "</tr>";
	
	for (var i = 1; i < a.length; i++){
		if (i % 2 == 1){
			even = "even";
		}
		else{
			even = "";
		}
		table += "<tr class='complaint " + even + "' id='ow_" + i + "'>";
		for (var j = 0; j < a[0].length; j++){
			if(j != 2){
				table += "<td>" + a[i][j] + "</td>";
			}
		}
		table += "</tr><tr><td id='row_" + i.toString() + "' class='descriptionRow " + even + "' colspan='" + (a[0].length - 1) + "'>" + a[i][2] + "</td></tr>";
	}
	table += "</table>";
	return table;
}

function showDescriptionOnHover(){
	$('.complaint').hover(function() {
        var id = "r" + $(this).attr('id');
        timeOut = setTimeout(function(){$('#' + id).show('fast');}, 800);
    },
    function() {
    	clearTimeout(timeOut);
    	var id = "r" + $(this).attr('id');
        $('#' + id).hide("fast");
    });
}

function makeTableSortable(){
	$(".myComplaintsTable th").click(
			function(){
				getMyComplaintsFromDB("'" + $(this).attr("id") + "'");
				makeTableSortable();
			}
	);
}